package com.ruoyi.pcwl.controller;

import java.util.List;
import java.util.Map;


import com.ruoyi.pcwl.domain.AppVedio;
import com.ruoyi.pcwl.domain.MediaFiles;
import com.ruoyi.pcwl.domain.dto.AppVedioDto;
import com.ruoyi.pcwl.domain.query.AppVedioQuery;
import com.ruoyi.pcwl.domain.vo.Result;
import com.ruoyi.pcwl.domain.enums.MediaTypeEnum;
import com.ruoyi.pcwl.minio.MinioUtil;
import com.ruoyi.pcwl.service.AppVedioService;
import com.ruoyi.pcwl.service.IMediaFilesService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 视频信息 Controller
 */

@Api(tags = "视频信息控制层")
@RestController("appVedioController")
@RequestMapping("/appVedio")
public class AppVedioController extends BaseController{

	@Value("${minio.bucketName}")
	private String bucketName;

	@Resource
	private AppVedioService appVedioService;

	@Autowired
	IMediaFilesService mediaFilesService;

	/**
	 * 根据条件分页查询
	 */
	@ApiOperation("根据条件分页查询")
	@GetMapping("/loadDataList")
	public Result loadDataList(AppVedioQuery query){
		return Result.ok(appVedioService.selectPage(query));
	}

	@ApiOperation("发布轮播到小程序")
//    @PreAuthorize("@ss.hasPermi('system:article:list')")
	@PutMapping("/publishVedio/{id}")
	public Result publishVedio(@PathVariable("id") String id) {
		appVedioService.publishVedio(id);
		return success();
	}

	/**
	 * 新增视频
	 */
	@ApiOperation("新增视频")
	@PostMapping("/addVedio")
	public Result addVedio(@RequestBody AppVedio bean) {

		appVedioService.save(bean);

		return Result.ok(null);
	}

//	/**
//	 * 新增视频
//	 */
//	@ApiOperation("新增视频")
//	@PostMapping("/addVedio")
//	public Result addVedio(AppVedioDto bean) {
//
//		//上传文件到minio
//		Map<String, Object> map = null;
//		try {
//			 map = MinioUtil.uploadFile(bean.getFile(), MediaTypeEnum.VEDIO);
//		} catch (Exception e) {
//			throw new RuntimeException("上传文件失败");
//		}
//		//保存轮播图信息
//		AppVedio appVedio = new AppVedio();
//		BeanUtils.copyProperties(bean,appVedio);
//		appVedio.setVedio(map.get("path").toString());
//		appVedio.setMediaFileId(Long.parseLong(map.get("mediaFileId").toString()));
//		appVedioService.save(appVedio);
//
//		return Result.ok(null);
//	}


	/**
	 * 新增
	 */
	@ApiOperation("新增")
	@PostMapping("/add")
	public Result add(@RequestBody AppVedio bean) {
		appVedioService.add(bean);
		return Result.ok(null);
	}

	/**
	 * 批量新增
	 */
	@ApiOperation("批量新增")
	@PostMapping("/addBatch")
	public Result addBatch(@RequestBody List<AppVedio> listBean) {
		appVedioService.addBatch(listBean);
		return Result.ok(null);
	}

	/**
	 * 批量新增/修改
	 */
	@ApiOperation("批量新增/修改")
	@PostMapping("/addOrUpdateBatch")
	public Result addOrUpdateBatch(@RequestBody List<AppVedio> listBean) {
		appVedioService.addBatch(listBean);
		return Result.ok(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@ApiOperation("根据Id查询对象")
	@GetMapping("/getAppVedioById/{id}")
	public Result getAppVedioById(@PathVariable Long id) {
		return Result.ok(appVedioService.getAppVedioById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@ApiOperation("根据Id修改对象")
	@PutMapping("/updateAppVedioById/{id}")
	public Result updateAppVedioById(@RequestBody AppVedio bean,@PathVariable Long id) {
		appVedioService.updateAppVedioById(bean);
		return Result.ok(null);
	}

	/**
	 * 根据Id删除
	 */

	@ApiOperation("根据Id删除")
	@DeleteMapping("/deleteAppVedioById/{id}")
	public Result deleteAppVedioById(@PathVariable Long id) {
		appVedioService.deleteAppVedioById(id);
		return Result.ok(null);
	}
}
